package com.xnfh.field.ui.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.xnfh.common.bean.TendencyYearBean
import com.xnfh.field.R
import com.xnfh.field.databinding.AdapterTendencyDateBinding
import java.util.Currency

/**
 * @Description:
 * @Author: ziheng
 * @CreateDate: 2023/12/6 17:23
 * @UpdateUser: ziheng
 * @UpdateDate: 2023/12/6 17:23
 * @UpdateRemark: 更新说明
 */
class TendencyYearAdapter :
    BaseQuickAdapter<TendencyYearBean, BaseDataBindingHolder<AdapterTendencyDateBinding>>(R.layout.adapter_tendency_date) {
    private var listener: onItemSelectYear? = null
    private var currSelect = 0
    override fun convert(
        holder: BaseDataBindingHolder<AdapterTendencyDateBinding>,
        item: TendencyYearBean
    ) {
        val dataBinding = holder.dataBinding
        holder.setText(R.id.item_tendency_date, item.year.toString())
        dataBinding?.itemTendencyDate?.setOnClickListener {
            if(currSelect != holder.layoutPosition){
                //取消上次选中的
                data[currSelect].isSelect = false
                notifyItemChanged(currSelect)
                //刷新当前选中的
                currSelect = holder.layoutPosition
                data[holder.layoutPosition].isSelect = true
                notifyItemChanged(currSelect)
                //回调给activity
                listener?.setSelect(currSelect)
            }
        }
    }

    interface onItemSelectYear {
        fun setSelect(position: Int)
    }

    fun setOnItemSelectYearListener(listener: onItemSelectYear) {
        this.listener = listener
    }
}